import * as actionTypes from "./constance";

import {
  getLyric,
  getCommentMusic,
  getSongDetail,
  getSimiSong,
  getSimiPlaylist,
} from "@/services/song";

const Lyric = (res) => ({
  type: actionTypes.GET_LYRIC,
  lyric: res,
});

const commentMusic = (res) => ({
  type: actionTypes.GET_COMMENTMUSIC,
  commentMusic: res,
});
const songDetail = (res) => ({
  type: actionTypes.GET_SONGDETAIL,
  songDetail: res,
});
const SimiSong = (res) => ({
  type: actionTypes.GET_SIMISONG,
  simiSong: res,
});
const simiPlaylist = (res) => ({
  type: actionTypes.GET_SIMIPLAYLIST,
  simiPlaylistInfo: res,
});
// 歌词
export const getLyricAction = (id) => {
  return (dispatch) => {
    getLyric(id).then((res) => {
      dispatch(Lyric(res));
    });
  };
};
// 评论
export const getCommentMusicAction = (id, limit, offset, before) => {
  return (dispatch) => {
    getCommentMusic(id, limit, offset, before).then((res) => {
      dispatch(commentMusic(res));
    });
  };
};
// 详情
export const getSongDetailAction = (ids) => {
  return (dispatch) => {
    getSongDetail(ids).then((res) => {
      dispatch(songDetail(res));
    });
  };
};
// 相似
export const getSimiSongAction = (id) => {
  return (dispatch) => {
    getSimiSong(id).then((res) => {
      dispatch(SimiSong(res));
    });
  };
};
// 包含这首歌的歌单
export const simiPlaylistAction = (id) => {
  return (dispatch) => {
    getSimiPlaylist(id).then((res) => {
      dispatch(simiPlaylist(res));
    });
  };
};
